#include <bits/stdc++.h>
using namespace std;
int days[1000010] = {0};
int usedNumbers[1000010] = {0};
int starts[1000010] = {0};
int ends1[1000010] = {0};
long long pre_n[1000010] = {0};
int m, n;
int ifOK(int x)
{
    for (int i = 0; i <= n; i++) pre_n[i] = 0;
    for (int i = 1; i <= x; i++)
    {
        for (int j = starts[i]; j <= ends1[i]; j++)
        {
            pre_n[j] += usedNumbers[i];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (pre_n[i] > days[i])
        {
            return 0;
        }
    }
    return 1;
}
int main(void)
{
    cin >> n >> m;
    int output = -1;
    for (int i = 1; i <= n; i++)
    {
        cin >> days[i];
    }
    for (int i = 1; i <= m; i++)
    {
        cin >> usedNumbers[i] >> starts[i] >> ends1[i];
    }
    int left = 1;
    int right = n;
    while (left <= right)
    {
        int mid = (left + right) >> 1;
        if (ifOK(mid))
        {
            left = mid + 1;
        }
        else
        {
            right = mid - 1;
            output = mid;
        }
    }
    if (output == -1)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << -1 << endl;
        cout << output;
    }
    return 0;
}